package com.dc.seckill.util;


import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @模块 参数模块
 * @作者 djs
 * @时间 2018/3/20 8:41
 * @版本 V1.0
 * @描述 MD5工具类，用来加密相关参数
 */
public class MD5Utils {

    private static Logger log = LoggerFactory.getLogger(MD5Utils.class);

    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    public static final String salt = "1a2b3c4d";

    public static String inputPassToFormPass(String inputPass){
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        log.info(str);
        return md5(str);
    }

    public static String formPassToDBPass(String fromPass, String salt){
        String str = "" + salt.charAt(0) + salt.charAt(2) + fromPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }

    public static String inputPassToDBPass(String input,String saltDB){
        String formPass = inputPassToFormPass(input);
        log.info(formPass);
        String dbpass = formPassToDBPass(formPass,saltDB);
        return dbpass;
    }

    @Test
    public void saveuser(){
        String frompass = inputPassToDBPass("123qwe","1ab23c4d");
        log.info(frompass);
    }

}
